<!DOCTYPE html>
<html  lang="zh">
<head>
    <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="utf-8" />

<meta name="generator" content="Hexo 3.9.0" />

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />

<title>shader学习21-深度和法线纹理-运动模糊 - 游戏人生</title>


    <meta name="description" content="shade学习">
<meta name="keywords" content="学习">
<meta property="og:type" content="article">
<meta property="og:title" content="shader学习21-深度和法线纹理-运动模糊">
<meta property="og:url" content="http://cloundgame.gitee.io/mystudy/2020/07/12/shader学习21-深度和法线纹理-运动模糊/index.html">
<meta property="og:site_name" content="游戏人生">
<meta property="og:description" content="shade学习">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://cloundgame.gitee.io/mystudy/images/og_image.png">
<meta property="og:updated_time" content="2020-07-13T07:46:48.275Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="shader学习21-深度和法线纹理-运动模糊">
<meta name="twitter:description" content="shade学习">
<meta name="twitter:image" content="http://cloundgame.gitee.io/mystudy/images/og_image.png">







<link rel="icon" href="/mystudy/images/favicon.svg">


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.7.2/css/bulma.css">
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.9.0/css/all.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/atom-one-dark.css">


    
    
    
    <style>body>.footer,body>.navbar,body>.section{opacity:0}</style>
    

    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/css/lightgallery.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/css/justifiedGallery.min.css">
    

    
    

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.css">


    
    
    
    

<link rel="stylesheet" href="/mystudy/css/back-to-top.css">


    
    

    
    
    
    

    
    
<link rel="stylesheet" href="/mystudy/css/progressbar.css">
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

    
    
    
        <script async="" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    

    


<link rel="stylesheet" href="/mystudy/css/style.css"><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</head>
<body class="is-3-column">
    <!-- hexo-inject:begin --><!-- hexo-inject:end --><nav class="navbar navbar-main">
    <div class="container">
        <div class="navbar-brand is-flex-center">
            <a class="navbar-item navbar-logo" href="/mystudy/">
            
                <img src="/mystudy/images/logo.svg" alt="shader学习21-深度和法线纹理-运动模糊" height="28">
            
            </a>
        </div>
        <div class="navbar-menu">
            
            <div class="navbar-start">
                
                <a class="navbar-item"
                href="/mystudy/">主页</a>
                
                <a class="navbar-item"
                href="/mystudy/archives">日志</a>
                
                <a class="navbar-item"
                href="/mystudy/categories">分类</a>
                
                <a class="navbar-item"
                href="/mystudy/">关于</a>
                
            </div>
            
            <div class="navbar-end">
                
                    
                    
                    <a class="navbar-item" target="_blank" title="Download on GitHub" href="https://github.com/koliy/koliy.github.io">
                        
                        <i class="fab fa-github"></i>
                        
                    </a>
                    
                
                
                <a class="navbar-item is-hidden-tablet catalogue" title="目录" href="javascript:;">
                    <i class="fas fa-list-ul"></i>
                </a>
                
                
                <a class="navbar-item search" title="搜索" href="javascript:;">
                    <i class="fas fa-search"></i>
                </a>
                
            </div>
        </div>
    </div>
</nav>
    
    <section class="section">
        <div class="container">
            <div class="columns">
                <div class="column is-8-tablet is-8-desktop is-6-widescreen has-order-2 column-main"><div class="card">
    
    <div class="card-content article ">
        
        <div class="level article-meta is-size-7 is-uppercase is-mobile is-overflow-x-auto">
            <div class="level-left">
                <time class="level-item has-text-grey" datetime="2020-07-12T07:09:47.000Z">2020-07-12</time>
                
                <div class="level-item">
                <a class="has-link-grey -link" href="/mystudy/categories/shade学习/">shade学习</a>
                </div>
                
                
                <span class="level-item has-text-grey">
                    
                    
                    16 分钟 读完 (大约 2405 个字)
                </span>
                
                
                <span class="level-item has-text-grey" id="busuanzi_container_page_pv">
                    <i class="far fa-eye"></i>
                    <span id="busuanzi_value_page_pv">0</span>次访问
                </span>
                
            </div>
        </div>
        
        <h1 class="title is-size-3 is-size-4-mobile has-text-weight-normal">
            
                shader学习21-深度和法线纹理-运动模糊
            
        </h1>
        <div class="content">
            <h2 id="运动模糊"><a href="#运动模糊" class="headerlink" title="运动模糊"></a><strong>运动模糊</strong></h2><p>一种应用更加广泛的技术是使用速度映射图，速度映射图中存储了每个像素的速度，然后使用这个速度来决定模糊的方向和大小。</p>
<a id="more"></a>
<h2 id="方法一："><a href="#方法一：" class="headerlink" title="方法一："></a><strong>方法一：</strong></h2><ul>
<li><p><strong>1.利用深度纹理在片元着色器中为每个像素计算其在世界空间下的位置，这个世界空间下的顶点坐标是通过使用当前摄像机的视角矩阵x投影矩阵的逆矩阵对NDC下顶点坐标进行变换得到。</strong></p>
</li>
<li><p><strong>2.当得到世界空间下的顶点坐标后，我们使用前一帧的摄像机的视角矩阵x投影矩阵对其进行变换，得到该位置在前一帧中的NDC坐标.</strong></p>
</li>
<li><p><strong>3.然后我们计算前一帧和当前帧的位置差，生成该像素的速度。</strong></p>
</li>
</ul>
<p><strong>此方法的优点是可以在一个屏幕后处理步骤中完成整个效果的模拟，缺点是需要在片元着色器中进行2次矩阵乘法的操作，对性能有影响</strong></p>
<p>简单的说：</p>
<ul>
<li><p><strong>1.通过当前摄像机的视角矩阵x投影矩阵的逆矩阵对NDC下顶点坐标变换获得该顶点的世界坐标</strong></p>
</li>
<li><p><strong>2.该顶点的世界坐标和前一帧的摄像机的视角矩阵x投影矩阵变换，得到该顶点在前一帧的NDC坐标</strong></p>
</li>
<li><p><strong>3.这样，通过当前帧的NDC坐标和前帧的NDC坐标的位置差，生成该像素的速度</strong></p>
</li>
</ul>
<h4 id="OnRenderImage"><a href="#OnRenderImage" class="headerlink" title="OnRenderImage"></a><strong>OnRenderImage</strong></h4><figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-comment">//上一帧摄像机的视角x投影矩阵</span></span><br><span class="line">private Matrix4x4 preViewProMatrix;</span><br><span class="line"></span><br><span class="line"><span class="hljs-keyword">void</span> OnEnable()</span><br><span class="line">&#123;</span><br><span class="line">    MyCamera.depthTextureMode |= DepthTextureMode.Depth;</span><br><span class="line">&#125;</span><br><span class="line"> <span class="hljs-keyword">void</span> OnRenderImage(RenderTexture src, RenderTexture dest)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="hljs-keyword">if</span>(material != <span class="hljs-literal">null</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        material.SetFloat(<span class="hljs-string">"_BlurSize"</span>, blurSize);</span><br><span class="line"></span><br><span class="line">        material.SetMatrix(<span class="hljs-string">"_PreViewProMatrix"</span>, preViewProMatrix);</span><br><span class="line">        <span class="hljs-comment">//当前摄像机的视角矩阵x投影矩阵</span></span><br><span class="line">        Matrix4x4 curViewProMatrix = MyCamera.projectionMatrix * MyCamera.worldToCameraMatrix;</span><br><span class="line">        <span class="hljs-comment">//当前摄像机的视角矩阵x投影矩阵的逆矩阵</span></span><br><span class="line">        Matrix4x4 curViewProInverMatrix = curViewProMatrix.inverse;</span><br><span class="line"></span><br><span class="line">        material.SetMatrix(<span class="hljs-string">"_CurViewProInverMatrix"</span>, curViewProInverMatrix);</span><br><span class="line">        preViewProMatrix = curViewProMatrix;</span><br><span class="line"></span><br><span class="line">        Graphics.Blit(src, dest, material);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="hljs-keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        Graphics.Blit(src, dest);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="Shader"><a href="#Shader" class="headerlink" title="Shader"></a><strong>Shader</strong></h4><figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br></pre></td><td class="code"><pre><span class="line">Shader <span class="hljs-string">"MyTest/Test7/test7-testMotionBlur"</span></span><br><span class="line">&#123;</span><br><span class="line">	Properties</span><br><span class="line">	&#123;</span><br><span class="line">		_MainTex (<span class="hljs-string">"Texture"</span>, <span class="hljs-number">2</span>D) = <span class="hljs-string">"white"</span> &#123;&#125;</span><br><span class="line">		_BlurSize(<span class="hljs-string">"Blur Size"</span>,float)=<span class="hljs-number">1.0</span></span><br><span class="line">	&#125;</span><br><span class="line">	SubShader</span><br><span class="line">	&#123;</span><br><span class="line">		Tags &#123; <span class="hljs-string">"RenderType"</span>=<span class="hljs-string">"Opaque"</span> &#125;</span><br><span class="line"></span><br><span class="line">		CGINCLUDE</span><br><span class="line">		</span><br><span class="line">			#include "UnityCG.cginc"</span><br><span class="line"></span><br><span class="line">			sampler2D _MainTex;</span><br><span class="line">			half4 _MainTex_TexelSize;</span><br><span class="line">			sampler2D _CameraDepthTexture;</span><br><span class="line">			<span class="hljs-comment">//当前帧的摄像机的视角矩阵x投影矩阵的逆矩阵</span></span><br><span class="line">			float4x4 _CurViewProInverMatrix;</span><br><span class="line">			<span class="hljs-comment">//前帧的摄像机的视角矩阵x投影矩阵</span></span><br><span class="line">			float4x4 _PreViewProMatrix;</span><br><span class="line"></span><br><span class="line">			fixed _BlurSize;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">			struct v2f</span><br><span class="line">			&#123;</span><br><span class="line">				float4 pos:SV_POSITION;</span><br><span class="line">				half2 uv : TEXCOORD0;</span><br><span class="line">				half2 uv_depth : TEXCOORD1;</span><br><span class="line">			&#125;;</span><br><span class="line">			</span><br><span class="line">			v2f vert (appdata_img v)</span><br><span class="line">			&#123;</span><br><span class="line">				v2f o;</span><br><span class="line">				o.pos = UnityObjectToClipPos(v.vertex);</span><br><span class="line">				o.uv = v.texcoord;</span><br><span class="line">				o.uv_depth = v.texcoord;</span><br><span class="line"></span><br><span class="line">				#if UNITY_UV_STARTS_AT_TOP</span><br><span class="line">				<span class="hljs-keyword">if</span>(_MainTex_TexelSize.y &lt; <span class="hljs-number">0</span>)</span><br><span class="line">					o.uv_depth.y = <span class="hljs-number">1</span>- o.uv_depth.y;</span><br><span class="line">				#endif</span><br><span class="line"></span><br><span class="line">				<span class="hljs-keyword">return</span> o;</span><br><span class="line">			&#125;</span><br><span class="line">			</span><br><span class="line">			fixed4 frag (v2f i) : SV_Target</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="hljs-comment">//获取该顶点的深度值</span></span><br><span class="line">				float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv_depth);</span><br><span class="line">				<span class="hljs-comment">//构建像素的NDC坐标矩阵，像素纹理范围为[0,1]进行反函数[-1,1],xy分量不变，保持uv的xy坐标，变化的是z分量</span></span><br><span class="line">				float4 H = float4(i.uv.x * <span class="hljs-number">2</span><span class="hljs-number">-1</span>,i.uv.y*<span class="hljs-number">2</span> <span class="hljs-number">-1</span>,d*<span class="hljs-number">2</span><span class="hljs-number">-1</span>,<span class="hljs-number">1</span>);</span><br><span class="line">				<span class="hljs-comment">//通过当前帧的摄像机的视角矩阵x投影矩阵的逆矩阵变换为世界空间下的坐标</span></span><br><span class="line">				float4 D = mul(_CurViewProInverMatrix , H);</span><br><span class="line">				<span class="hljs-comment">//使用结果中的w分量，进行齐次除法得到归一化后的世界坐标.</span></span><br><span class="line">				float4 worldPos = D/D.w;</span><br><span class="line">				</span><br><span class="line">				<span class="hljs-comment">//使用世界空间下的顶点坐标和前帧的摄像机的视角矩阵x投影矩阵变换，获得NDC坐标矩阵</span></span><br><span class="line">				float4 preViewPos = mul(_PreViewProMatrix,worldPos);</span><br><span class="line">				preViewPos /= preViewPos.w;</span><br><span class="line">				</span><br><span class="line">				<span class="hljs-comment">//当前帧的NDC矩阵坐标和前帧NDC矩阵坐标做差值运算，获得速度</span></span><br><span class="line">				float4 currentPos = H;</span><br><span class="line">				float2 velocity = (currentPos.xy - preViewPos.xy)/<span class="hljs-number">2.0</span>f;</span><br><span class="line"></span><br><span class="line">				<span class="hljs-comment">//取UV偏移后的平均值</span></span><br><span class="line">				float2 uv = i.uv;</span><br><span class="line">				float4 c = tex2D(_MainTex,uv);</span><br><span class="line">				uv += velocity*_BlurSize;</span><br><span class="line">				<span class="hljs-keyword">for</span>(int it =<span class="hljs-number">1</span>;it&lt;<span class="hljs-number">3</span>;it++,uv+=velocity*_BlurSize)&#123;</span><br><span class="line">					float4 curColor = tex2D(_MainTex,uv);</span><br><span class="line">					c += curColor;</span><br><span class="line">				&#125;</span><br><span class="line">				c /= <span class="hljs-number">3</span>;</span><br><span class="line"></span><br><span class="line">				<span class="hljs-keyword">return</span> fixed4(c.rgb,<span class="hljs-number">1</span>);</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">		ENDCG</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">		Pass</span><br><span class="line">		&#123;</span><br><span class="line">			ZTest Always </span><br><span class="line">			Cull Off</span><br><span class="line">			ZWrite Off</span><br><span class="line"></span><br><span class="line">			CGPROGRAM</span><br><span class="line">			#pragma vertex vert</span><br><span class="line">			#pragma fragment frag</span><br><span class="line"></span><br><span class="line">			ENDCG</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="注意"><a href="#注意" class="headerlink" title="注意"></a><strong>注意</strong></h4><p>本例的运动模糊只适用于场景静止，摄像机快速运动的情况，因为我们只考虑了摄像机的运动，如果要应用到一个物体快速运动而摄像机静止的场景，则不会有模糊效果。想要实现此效果可以在unity自带的ImageEffect包中找到。</p>
<h2 id="方法二"><a href="#方法二" class="headerlink" title="方法二:"></a><strong>方法二:</strong></h2><p>方法一往往会影响性能，这里介绍一种更快速的由深度纹理重建世界坐标的方法。</p>
<h4 id="原理："><a href="#原理：" class="headerlink" title="原理："></a><strong>原理：</strong></h4><p>我们知道，坐标系中的一个顶点坐标可以通过它相对于另一个顶点坐标的偏移量求得。因此，我们只需要知道摄像机在世界空间下的位置，以及世界空间下该像素相对于摄像机的偏移量，把它们相加就是该顶点的世界坐标。</p>
<ul>
<li><strong>1，首先对图像空间下的视锥体射线(从摄像机出发，指向图像上的某点的射线)进行插值，这条射线存储了该像素在世界空间下到摄像机的方向信息</strong></li>
<li><strong>2. 然后，我们把该射线和线性化后的视角空间下的深度值相乘，再加上摄像机的世界坐标，得到该像素在世界空间下的坐标</strong></li>
</ul>
<p><strong>公式:</strong><br><strong>float4 worldPos = _WorldSpaceCameraPos + LinearDepth * interpolatedRay;</strong></p>
<ul>
<li><strong>_WorldSpaceCameraPos: Unity内置的摄像机世界坐标变量</strong></li>
<li><strong>LinearDepth: 由深度纹理得到的线性深度值，是摄像机视角空间下的线性深度值</strong></li>
<li><strong>interpolatedRay: 由顶点着色器输出并插值后得到的射线，它包含该像素到摄像机的方向和距离</strong></li>
</ul>
<h4 id="interpolatedRay求法"><a href="#interpolatedRay求法" class="headerlink" title="interpolatedRay求法"></a><strong>interpolatedRay求法</strong></h4><p>interpolatedRay来源于对近裁剪平面的4个角的某个特定向量的插值，这4个向量包含了它们到摄像机的方向和距离信息，我们可以利用摄像机的近裁剪平面距离，FOV，横纵比计算而得</p>
<p>$$ halfHeight = Near * tan\left(\frac{FOV}{2}\right)$$<br>$$toTop = camera.up * halfHeight$$<br>$$toRight = camera.right * halfHeight * camera.aspect$$</p>
<p>其中Near近裁剪平面的距离，FOV是竖直方向的视角范围，camera.up,camera.right分别对应摄像机的正上方和正右方。<br>toTop,toRight: 它们是起点位于近裁剪平面中心，分别指向摄像机正上方和正右方的向量，也就是近裁剪平面的正上方和正右方。</p>
<p><strong>根据这2个辅助向量，可以计算近裁剪平面4个角相对摄像机的方向了:</strong><br>$左上角 ：TL=camera.forward * Near + toTop - toRight$<br>$右上角 ：TL=camera.forward * Near + toTop + toRight$<br>$左下角 ：TL=camera.forward * Near - toTop - toRight$<br>$右下角 ：TL=camera.forward * Near - toTop + toRight$</p>
<p>因此需要计算从摄像机到图像上的像素点射线，需要先计算该点在对应近裁剪平面4个角上，摄像机对4个角的射线的延长线上的点。<br>如图:<br><img src="unity1.png" alt></p>
<p>以TL点为例，根据三角形原理,TL所在的射线上，像素的深度值和它到摄像机的实际距离比等于近裁剪平面的距离和TL向量的摸的比：<br>$$sin\theta = \frac{Near}{|TL|} = \frac{depth}{dest}$$<br>$$dist = \frac{|TL|}{Near}* depth$$<br>由于4个点相对对称，因此其他3个向量的摸和TL相等:<br>$$scale = \frac{|TL|}{|Near|}$$<br>这样可以知道，通过放大scale倍，和TL的单位向量相乘，就是我们需要的dist射线。<br>$$RAY_{tl}=\frac{TL}{|TL|}*scale$$</p>
<p><strong>最后：</strong><br>屏幕后处理的原理是使用特定的材质去渲染一个刚好填充整个屏幕的四边形。这个四边形面片的4个顶点就对应了近裁剪平面4个角。因此，我们可以把上面的计算结果传递给顶点着色器，顶点着色器根据当前的位置选择它所对应的向量，然后在将其输出，经插值后传递给片元着色器得到interpolatedRay。</p>
<h4 id="OnRenderImage-1"><a href="#OnRenderImage-1" class="headerlink" title="OnRenderImage"></a><strong>OnRenderImage</strong></h4><figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="hljs-comment">//上一帧四边形</span></span><br><span class="line">private Matrix4x4 preViewProMatrix;</span><br><span class="line"></span><br><span class="line"><span class="hljs-keyword">void</span> OnEnable()</span><br><span class="line">&#123;</span><br><span class="line">    MyCamera.depthTextureMode |= DepthTextureMode.Depth;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="hljs-keyword">void</span> OnRenderImage(RenderTexture src, RenderTexture dest)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="hljs-keyword">if</span> (material != <span class="hljs-literal">null</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        material.SetFloat(<span class="hljs-string">"_BlurSize"</span>, blurSize);</span><br><span class="line">        material.SetMatrix(<span class="hljs-string">"_PreViewProMatrix"</span>, preViewProMatrix);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        Matrix4x4 frustumCorners = Matrix4x4.identity;</span><br><span class="line">        float fov = MyCamera.fieldOfView;</span><br><span class="line">        float near = MyCamera.nearClipPlane;</span><br><span class="line">        float far = MyCamera.farClipPlane;</span><br><span class="line">        float aspect = MyCamera.aspect;</span><br><span class="line"></span><br><span class="line">        float halfHeight = near * Mathf.Tan(fov * <span class="hljs-number">0.5</span>f * Mathf.Deg2Rad);</span><br><span class="line">        Vector3 toRight = MyCameraTran.right * halfHeight * aspect;</span><br><span class="line">        Vector3 toTop = MyCameraTran.up * halfHeight;</span><br><span class="line"></span><br><span class="line">        Vector3 topLeft = MyCameraTran.forward * near + toTop - toRight;</span><br><span class="line">        float scale = topLeft.magnitude / near;</span><br><span class="line"></span><br><span class="line">        topLeft.Normalize();</span><br><span class="line">        topLeft *= scale;</span><br><span class="line"></span><br><span class="line">        Vector3 topRight = MyCameraTran.forward * near + toRight + toTop;</span><br><span class="line">        topRight.Normalize();</span><br><span class="line">        topRight *= scale;</span><br><span class="line"></span><br><span class="line">        Vector3 botLeft = MyCameraTran.forward * near - toRight - toTop;</span><br><span class="line">        botLeft.Normalize();</span><br><span class="line">        botLeft *= scale;</span><br><span class="line"></span><br><span class="line">        Vector3 botRight = MyCameraTran.forward * near + toRight - toTop;</span><br><span class="line">        botRight.Normalize();</span><br><span class="line">        botRight *= scale;</span><br><span class="line"></span><br><span class="line">        <span class="hljs-comment">//注意顺序</span></span><br><span class="line">        frustumCorners.SetRow(<span class="hljs-number">0</span>, botLeft);</span><br><span class="line">        frustumCorners.SetRow(<span class="hljs-number">1</span>, botRight);</span><br><span class="line">        frustumCorners.SetRow(<span class="hljs-number">2</span>, topRight);</span><br><span class="line">        frustumCorners.SetRow(<span class="hljs-number">3</span>, topLeft);</span><br><span class="line"></span><br><span class="line">        preViewProMatrix = frustumCorners;</span><br><span class="line"></span><br><span class="line">        material.SetMatrix(<span class="hljs-string">"_FrustumCornersRay"</span>, frustumCorners);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        Graphics.Blit(src, dest, material);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="hljs-keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        Graphics.Blit(src, dest);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="Shader-1"><a href="#Shader-1" class="headerlink" title="Shader"></a><strong>Shader</strong></h4><figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br></pre></td><td class="code"><pre><span class="line">Shader <span class="hljs-string">"MyTest/Test7/test7-testMotionBlur2"</span></span><br><span class="line">&#123;</span><br><span class="line">	Properties</span><br><span class="line">	&#123;</span><br><span class="line">		_MainTex (<span class="hljs-string">"Texture"</span>, <span class="hljs-number">2</span>D) = <span class="hljs-string">"white"</span> &#123;&#125;</span><br><span class="line">		_BlurSize(<span class="hljs-string">"Blur Size"</span>,float)=<span class="hljs-number">1.0</span></span><br><span class="line">	&#125;</span><br><span class="line">	SubShader</span><br><span class="line">	&#123;</span><br><span class="line">		Tags &#123; <span class="hljs-string">"RenderType"</span>=<span class="hljs-string">"Opaque"</span> &#125;</span><br><span class="line"></span><br><span class="line">		CGINCLUDE</span><br><span class="line">		</span><br><span class="line">			#include "UnityCG.cginc"</span><br><span class="line"></span><br><span class="line">			sampler2D _MainTex;</span><br><span class="line">			half4 _MainTex_TexelSize;</span><br><span class="line">			sampler2D _CameraDepthTexture;</span><br><span class="line"></span><br><span class="line">			<span class="hljs-comment">//前帧的摄像机的视角矩阵x投影矩阵</span></span><br><span class="line">			float4x4 _PreViewProMatrix;</span><br><span class="line"></span><br><span class="line">			<span class="hljs-comment">//当前射线四边形</span></span><br><span class="line">			float4x4 _FrustumCornersRay;</span><br><span class="line"></span><br><span class="line">			fixed _BlurSize;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">			struct v2f</span><br><span class="line">			&#123;</span><br><span class="line">				float4 pos:SV_POSITION;</span><br><span class="line">				half2 uv : TEXCOORD0;</span><br><span class="line">				half2 uv_depth : TEXCOORD1;</span><br><span class="line">				float4 interpolatedRay1:TEXCOORD2;</span><br><span class="line">				float4 interpolatedRay2:TEXCOORD3;</span><br><span class="line">			&#125;;</span><br><span class="line">			</span><br><span class="line">			v2f vert (appdata_img v)</span><br><span class="line">			&#123;</span><br><span class="line">				v2f o;</span><br><span class="line">				o.pos = UnityObjectToClipPos(v.vertex);</span><br><span class="line">				o.uv = v.texcoord;</span><br><span class="line">				o.uv_depth = v.texcoord;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">				int index =<span class="hljs-number">0</span>;</span><br><span class="line">				<span class="hljs-keyword">if</span>(v.texcoord.x &lt; <span class="hljs-number">0.5</span> &amp;&amp; v.texcoord.y &lt; <span class="hljs-number">0.5</span>)&#123;</span><br><span class="line">					index = <span class="hljs-number">0</span>;</span><br><span class="line">				&#125;<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(v.texcoord.x &gt; <span class="hljs-number">0.5</span> &amp;&amp; v.texcoord.y &lt; <span class="hljs-number">0.5</span>)&#123;</span><br><span class="line">					index = <span class="hljs-number">1</span>;</span><br><span class="line">				&#125;<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(v.texcoord.x &gt; <span class="hljs-number">0.5</span> &amp;&amp; v.texcoord.y &gt; <span class="hljs-number">0.5</span>)&#123;</span><br><span class="line">					index = <span class="hljs-number">2</span>;</span><br><span class="line">				&#125;<span class="hljs-keyword">else</span>&#123;</span><br><span class="line">					index =<span class="hljs-number">3</span>;</span><br><span class="line">				&#125;</span><br><span class="line"></span><br><span class="line">				#if UNITY_UV_STARTS_AT_TOP</span><br><span class="line">				<span class="hljs-keyword">if</span>(_MainTex_TexelSize.y &lt; <span class="hljs-number">0</span>)&#123;</span><br><span class="line">					o.uv_depth.y = <span class="hljs-number">1</span>- o.uv_depth.y;</span><br><span class="line">					index = <span class="hljs-number">3</span> - index;</span><br><span class="line">				&#125;</span><br><span class="line">				#endif</span><br><span class="line"></span><br><span class="line">				o.interpolatedRay1 = _FrustumCornersRay[index];</span><br><span class="line">				o.interpolatedRay2 = _PreViewProMatrix[index];</span><br><span class="line">				<span class="hljs-keyword">return</span> o;</span><br><span class="line">			&#125;</span><br><span class="line">			</span><br><span class="line">			fixed4 frag (v2f i) : SV_Target</span><br><span class="line">			&#123;</span><br><span class="line">				<span class="hljs-comment">//获取该顶点的深度值</span></span><br><span class="line">				float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,i.uv_depth);</span><br><span class="line">				float linearDepth = LinearEyeDepth(d);</span><br><span class="line"></span><br><span class="line">				float3 worldPos1 = _WorldSpaceCameraPos + linearDepth * i.interpolatedRay1.xyz;</span><br><span class="line">				float3 worldPos2 = _WorldSpaceCameraPos + linearDepth * i.interpolatedRay2.xyz;</span><br><span class="line"></span><br><span class="line">				float2 velocity = (worldPos1.xy - worldPos2.xy)/<span class="hljs-number">2.0</span>f;</span><br><span class="line"></span><br><span class="line">				<span class="hljs-comment">//取UV偏移后的平均值</span></span><br><span class="line">				float2 uv = i.uv;</span><br><span class="line">				float4 c = tex2D(_MainTex,uv);</span><br><span class="line">				uv += velocity*_BlurSize;</span><br><span class="line">				<span class="hljs-keyword">for</span>(int it =<span class="hljs-number">1</span>;it&lt;<span class="hljs-number">3</span>;it++,uv+=velocity*_BlurSize)&#123;</span><br><span class="line">					float4 curColor = tex2D(_MainTex,uv);</span><br><span class="line">					c += curColor;</span><br><span class="line">				&#125;</span><br><span class="line">				c /= <span class="hljs-number">3</span>;</span><br><span class="line"></span><br><span class="line">				<span class="hljs-keyword">return</span> fixed4(c.rgb,<span class="hljs-number">1</span>);</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">		ENDCG</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">		Pass</span><br><span class="line">		&#123;</span><br><span class="line">			ZTest Always </span><br><span class="line">			Cull Off</span><br><span class="line">			ZWrite Off</span><br><span class="line"></span><br><span class="line">			CGPROGRAM</span><br><span class="line">			#pragma vertex vert</span><br><span class="line">			#pragma fragment frag</span><br><span class="line"></span><br><span class="line">			ENDCG</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


        </div>
        
        <div class="level is-size-7 is-uppercase">
            <div class="level-start">
                <div class="level-item">
                    <span class="is-size-6 has-text-grey has-mr-7">#</span>
                    <a class="has-link-grey -link" href="/mystudy/tags/学习/">学习</a>
                </div>
            </div>
        </div>
        
        

        
        <div class="social-share"></div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/css/share.min.css">
<script src="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/js/social-share.min.js"></script>
        
    </div>
</div>





<div class="card card-transparent">
    <div class="level post-navigation is-flex-wrap is-mobile">
        
        <div class="level-start">
            <a class="level level-item has-link-grey  article-nav-prev" href="/mystudy/2020/07/13/shader学习21-深度和法线纹理-全局雾效/">
                <i class="level-item fas fa-chevron-left"></i>
                <span class="level-item">shader学习21-深度和法线纹理-全局雾效</span>
            </a>
        </div>
        
        
        <div class="level-end">
            <a class="level level-item has-link-grey  article-nav-next" href="/mystudy/2020/07/11/shader学习21-深度和法线纹理/">
                <span class="level-item">shader学习21-深度和法线纹理</span>
                <i class="level-item fas fa-chevron-right"></i>
            </a>
        </div>
        
    </div>
</div>


</div>
                




<div class="column is-4-tablet is-4-desktop is-3-widescreen  has-order-1 column-left ">
    
        
<div class="card widget">
    <div class="card-content">
        <nav class="level">
            <div class="level-item has-text-centered" style="flex-shrink: 1">
                <div>
                    
                        <img class="image is-128x128 has-mb-6" src="/mystudy/images/avatar2.jpg" alt="满头大汉老黄牛">
                    
                    
                    <p class="is-size-4 is-block">
                        满头大汉老黄牛
                    </p>
                    
                    
                    <p class="is-size-6 is-block">
                        游戏
                    </p>
                    
                    
                    <p class="is-size-6 is-flex is-flex-center has-text-grey">
                        <i class="fas fa-map-marker-alt has-mr-7"></i>
                        <span>火星</span>
                    </p>
                    
                </div>
            </div>
        </nav>
        <nav class="level is-mobile">
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        文章
                    </p>
                    <p class="title has-text-weight-normal">
                        70
                    </p>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        分类
                    </p>
                    <p class="title has-text-weight-normal">
                        10
                    </p>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        标签
                    </p>
                    <p class="title has-text-weight-normal">
                        3
                    </p>
                </div>
            </div>
        </nav>
        <div class="level">
            <a class="level-item button is-link is-rounded" href="https://github.com/koliy/" target="_blank">
                关注我</a>
        </div>
        
        
        <div class="level is-mobile">
            
            <a class="level-item button is-white is-marginless" target="_blank"
                title="Github" href="https://github.com/koliy/">
                
                <i class="fab fa-github"></i>
                
            </a>
            
        </div>
        
    </div>
</div>
    
        


    
        
<div class="card widget">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                分类
            </h3>
            <ul class="menu-list">
            <li>
        <a class="level is-marginless" href="/mystudy/categories/3D数学基础-图形与游戏开发/">
            <span class="level-start">
                <span class="level-item">3D数学基础:图形与游戏开发</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">3</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/AI/">
            <span class="level-start">
                <span class="level-item">AI</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">12</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/MySql/">
            <span class="level-start">
                <span class="level-item">MySql</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/SurfaceShader/">
            <span class="level-start">
                <span class="level-item">SurfaceShader</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/Unity/">
            <span class="level-start">
                <span class="level-item">Unity</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/git/">
            <span class="level-start">
                <span class="level-item">git</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">3</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/shade学习/">
            <span class="level-start">
                <span class="level-item">shade学习</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">33</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/xlua/">
            <span class="level-start">
                <span class="level-item">xlua</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/网络同步/">
            <span class="level-start">
                <span class="level-item">网络同步</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">10</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/设计模式/">
            <span class="level-start">
                <span class="level-item">设计模式</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">5</span>
            </span>
        </a></li>
            </ul>
        </div>
    </div>
</div>
    
        <div class="card widget">
    <div class="card-content">
        <div class="menu">
        <h3 class="menu-label">
            归档
        </h3>
        <ul class="menu-list">
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/09/">
                <span class="level-start">
                    <span class="level-item">九月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/07/">
                <span class="level-start">
                    <span class="level-item">七月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">23</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/06/">
                <span class="level-start">
                    <span class="level-item">六月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">17</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/03/">
                <span class="level-start">
                    <span class="level-item">三月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/02/">
                <span class="level-start">
                    <span class="level-item">二月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">4</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2019/09/">
                <span class="level-start">
                    <span class="level-item">九月 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">5</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2019/08/">
                <span class="level-start">
                    <span class="level-item">八月 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">18</span>
                </span>
            </a>
        </li>
        
        </ul>
        </div>
    </div>
</div>
    
        
<div class="card widget">
    <div class="card-content">
        <h3 class="menu-label">
            标签云
        </h3>
        <a href="/mystudy/tags/game/" style="font-size: 15px;">game</a> <a href="/mystudy/tags/git/" style="font-size: 10px;">git</a> <a href="/mystudy/tags/学习/" style="font-size: 20px;">学习</a>
    </div>
</div>

    
    
        <div class="column-right-shadow is-hidden-widescreen is-sticky">
        
            
<div class="card widget" id="toc">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                目录
            </h3>
            <ul class="menu-list"><li>
        <a class="is-flex" href="#运动模糊">
        <span class="has-mr-6">1</span>
        <span>运动模糊</span>
        </a></li><li>
        <a class="is-flex" href="#方法一：">
        <span class="has-mr-6">2</span>
        <span>方法一：</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#OnRenderImage">
        <span class="has-mr-6">2.1</span>
        <span>OnRenderImage</span>
        </a></li><li>
        <a class="is-flex" href="#Shader">
        <span class="has-mr-6">2.2</span>
        <span>Shader</span>
        </a></li><li>
        <a class="is-flex" href="#注意">
        <span class="has-mr-6">2.3</span>
        <span>注意</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#方法二">
        <span class="has-mr-6">3</span>
        <span>方法二:</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#原理：">
        <span class="has-mr-6">3.1</span>
        <span>原理：</span>
        </a></li><li>
        <a class="is-flex" href="#interpolatedRay求法">
        <span class="has-mr-6">3.2</span>
        <span>interpolatedRay求法</span>
        </a></li><li>
        <a class="is-flex" href="#OnRenderImage-1">
        <span class="has-mr-6">3.3</span>
        <span>OnRenderImage</span>
        </a></li><li>
        <a class="is-flex" href="#Shader-1">
        <span class="has-mr-6">3.4</span>
        <span>Shader</span>
        </a></li></ul></li></ul>
        </div>
    </div>
</div>

        
        </div>
    
</div>

                




<div class="column is-4-tablet is-4-desktop is-3-widescreen is-hidden-touch is-hidden-desktop-only has-order-3 column-right is-sticky">
    
        
<div class="card widget" id="toc">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                目录
            </h3>
            <ul class="menu-list"><li>
        <a class="is-flex" href="#运动模糊">
        <span class="has-mr-6">1</span>
        <span>运动模糊</span>
        </a></li><li>
        <a class="is-flex" href="#方法一：">
        <span class="has-mr-6">2</span>
        <span>方法一：</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#OnRenderImage">
        <span class="has-mr-6">2.1</span>
        <span>OnRenderImage</span>
        </a></li><li>
        <a class="is-flex" href="#Shader">
        <span class="has-mr-6">2.2</span>
        <span>Shader</span>
        </a></li><li>
        <a class="is-flex" href="#注意">
        <span class="has-mr-6">2.3</span>
        <span>注意</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#方法二">
        <span class="has-mr-6">3</span>
        <span>方法二:</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#原理：">
        <span class="has-mr-6">3.1</span>
        <span>原理：</span>
        </a></li><li>
        <a class="is-flex" href="#interpolatedRay求法">
        <span class="has-mr-6">3.2</span>
        <span>interpolatedRay求法</span>
        </a></li><li>
        <a class="is-flex" href="#OnRenderImage-1">
        <span class="has-mr-6">3.3</span>
        <span>OnRenderImage</span>
        </a></li><li>
        <a class="is-flex" href="#Shader-1">
        <span class="has-mr-6">3.4</span>
        <span>Shader</span>
        </a></li></ul></li></ul>
        </div>
    </div>
</div>

    
    
</div>

            </div>
        </div>
    </section>
    <footer class="footer">
    <div class="container1">
        <div class="level1">
            <div class="level-start1 has-text-centered-mobile1">
                <a class="footer-logo is-block has-mb-6" href="/mystudy/">
                

                
                </a>
                <p class="is-size-7">
                &copy; 2020 Koliy&nbsp;
                Powered by <a href="https://github.com/koliy/koliy.github.io" target="_blank">Hexo</a> & <a
                        href="https://github.com/ppoffice/hexo-theme-icarus" target="_blank">Icarus</a>
                
                <br>
                <span id="busuanzi_container_site_uv">
                共<span id="busuanzi_value_site_uv">0</span>个访客
                </span>
                
                </p>
            </div>
            <div class="level-end1">
            
            </div>
        </div>
    </div>
</footer>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/min/moment-with-locales.min.js"></script>
<script>moment.locale("zh-CN");</script>

<script>
var IcarusThemeSettings = {
    article: {
        highlight: {
            clipboard: true,
            fold: 'unfolded'
        }
    }
};
</script>


    <script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.4/dist/clipboard.min.js" defer></script>



    
    
    
    <script src="/mystudy/js/animation.js"></script>
    

    
    
    
    <script src="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/js/lightgallery.min.js" defer></script>
    <script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js" defer></script>
    <script src="/mystudy/js/gallery.js" defer></script>
    

    
    

<div id="outdated">
    <h6>Your browser is out-of-date!</h6>
    <p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update
            my browser now </a></p>
    <p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">&times;</a></p>
</div>
<script src="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js" defer></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        outdatedBrowser({
            bgColor: '#f25648',
            color: '#ffffff',
            lowerThan: 'flex'
        });
    });
</script>


    
    
<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/unpacked/MathJax.js?config=TeX-MML-AM_CHTML" defer></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
    MathJax.Hub.Config({
        'HTML-CSS': {
            matchFontHeight: false
        },
        SVG: {
            matchFontHeight: false
        },
        CommonHTML: {
            matchFontHeight: false
        },
        tex2jax: {
            inlineMath: [
                ['$','$'],
                ['\\(','\\)']
            ]
        }
    });
});
</script>

    
    

<a id="back-to-top" title="回到顶端" href="javascript:;">
    <i class="fas fa-chevron-up"></i>
</a>
<script src="/mystudy/js/back-to-top.js" defer></script>


    
    

    
    
    
    

    
    
    
    
    

    


<script src="/mystudy/js/main.js" defer></script>

    
    <div class="searchbox ins-search">
    <div class="searchbox-container ins-search-container">
        <div class="searchbox-input-wrapper">
            <input type="text" class="searchbox-input ins-search-input" placeholder="想要查找什么..." />
            <span class="searchbox-close ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="searchbox-result-wrapper ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: '文章',
                PAGES: '页面',
                CATEGORIES: '分类',
                TAGS: '标签',
                UNTITLED: '(无标题)',
            },
            CONTENT_URL: '/mystudy/content.json',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script src="/mystudy/js/insight.js" defer></script>
<link rel="stylesheet" href="/mystudy/css/search.css">
<link rel="stylesheet" href="/mystudy/css/insight.css"><!-- hexo-inject:begin --><!-- Begin: Injected MathJax -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({"tex2jax":{"inlineMath":[["$","$"],["\\(","\\)"]],"skipTags":["script","noscript","style","textarea","pre","code"],"processEscapes":true},"TeX":{"equationNumbers":{"autoNumber":"AMS"}}});
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
      all[i].SourceElement().parentNode.className += ' has-jax';
    }
  });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js">
</script>
<!-- End: Injected MathJax -->
<!-- hexo-inject:end -->
    
</body>
</html>